package main

func productExceptSelf(nums []int) []int {
	leftProduct := make([]int, len(nums))
	leftProduct[0] = 1
	for i := range nums {
		if i == 0 {
			continue
		}
		leftProduct[i] = leftProduct[i-1] * nums[i-1]
	}
	rightProduct := make([]int, len(nums))
	rightProduct[len(nums)-1] = 1
	for i := len(nums) - 2; i >= 0; i-- {
		rightProduct[i] = rightProduct[i+1] * nums[i+1]
	}
	result := make([]int, len(nums))
	for i := range nums {
		result[i] = leftProduct[i] * rightProduct[i]
	}
	return result
}

func main() {
	result := productExceptSelf([]int{1, 2, 3, 4})
	println(result)
}
